package com.sunchis.demo;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;

import com.sunchis.demo.util.ConfigFactory;
import com.sunchis.demo.util.jgroup.JGroupAgent;

@SuppressWarnings("serial")
public class InitAgentDiscoverServlet extends HttpServlet {
	@Override
	public void init(ServletConfig config) throws ServletException {
		super.init(config);
		new Thread(runnable).start();
	}
	
	Runnable runnable = new Runnable() {
		@Override
		public void run() {
//			AgentDiscover agentDiscover = null;
//			try {
//				agentDiscover = new AgentDiscover(null);
//				while (true) {  
//		        	String data = agentDiscover.receive();
//		        	System.out.println(data);
//		        } 
//			} catch (Exception e) {
//				e.printStackTrace();
//			} finally {
//				agentDiscover.close();
//			}
			
			try {
				JGroupAgent jGroupAgent = new JGroupAgent();
				ConfigFactory.getInstance().setjGroupAgent(jGroupAgent);
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
	};
}
